<?php
require_once('config.php');
require_once('db.php');
$link = connectdb($servername,$dbname,$dbusername,$dbpassword);
$id= $_GET['id'];
$sql="SELECT * FROM $dbtable WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<div align="center">
<h1>Site Information</h1>
</div>
<form name="Update" method="post" action="updatesite_ac.php"><input
	name="id" type="hidden" id="id" value="<?php echo $rows['id']; ?>" />
<input 	type="hidden" value="" id="hidCheck" name="hidCheck">
<input 	type="hidden" value="" id="showCheck" name="showCheck">
<table width="50%" style="margin-left: 25%" border="1" cellspacing="1"
	cellpadding="0">
	<tr>
		<td>
		<table width="400" border="0" cellspacing="0" cellpadding="3" style="margin-top: 2%;">
			<tr>
				<td align="right"><strong>Hostname: </strong></td>
				<td align="left"><input name="url" type="text" id="url"
					value="<?php echo $rows['hostname']; ?>"></td>
			</tr>
			<tr>
				<td align="right"><strong>Status: </strong></td>
				<td align="left"><select name="pause" id="pause">
					<option value="0"
					<?php if(trim($rows['pause']) === "0") echo "selected=\"selected\"";?>>Enable</option>
					<option value="1"
					<?php if(trim($rows['pause']) === "1") echo "selected=\"selected\"";?>>Disable</option>
				</select></td>
			</tr>
			<tr>
				<td align="right"><strong>Checking rate: </strong></td>
				<td align="left"><input name="checking_rate" type="text" id="checking_rate" size="5"
					value="<?php echo $rows['checking_rate']; ?>">(minute/time)</td>
			</tr>
			<tr>
			</tr>
		</table>
		<?php
		//Add information about protocols of site
		//$siteid = $id;
		$sql = "SELECT protocols.name AS Name, protocols.port AS Port, protocols.id AS ID, site_protocol.site_id AS Site_id FROM protocols LEFT JOIN site_protocol ON (protocols.id = site_protocol.protocol_id)";
		$sql .= " WHERE site_protocol.site_id = $id";
		$result= mysql_query($sql) or die('Error, insert query failed');
		?> <br>
		<table width="100%" border="0" cellspacing="0" cellpadding="3">
			<tr>
				<td align="center" colspan="1"><strong>Available Protocols</strong></td>
			</tr>
			<?php

			while($rows=mysql_fetch_array($result))
			{

				echo "<tr><td align=\"left\" style=\"padding-left: 30%\"><input checked type=checkbox name='avai[]' value=" . $rows['ID']. ">" . $rows['Name']
				. " Port: ". $rows['Port'] . "</td>"
				. "</tr>";

			}
			?>
		</table>
		<br>
		<?php
		$sql = "SELECT protocols.id as ID, protocols.name as Name, protocols.port as Port FROM protocols";
		$sql .= " WHERE protocols.id NOT IN (";
		$sql2 = "SELECT site_protocol.protocol_id FROM site_protocol WHERE site_protocol.site_id = '$id'";
		$sql .= $sql2 .")";
		$result = mysql_query($sql) or die('Error, insert query failed');
		?>
		<table width="100%" border="0" cellspacing="0" cellpadding="3">
			<tr>
				<td align="center"><strong>New Protocols for site</strong>
				</td>
			</tr>
			<?php
			while($rows=mysql_fetch_array($result))
			{

				echo "<tr>"
				. "<td align=\"left\"  style=\"padding-left: 30%\"><input type=checkbox name='newp[]' value=" . $rows['ID'] . ">" .$rows['Name']
				. " Port: ". $rows['Port']. "</td>"
				. "</tr>";
			}

			?>
			<tr>
				<td align="center"><input type="button"
					onclick="javascript:formSubmit(this);" name="Submit"
					value="Submit"></td>
			</tr>
		</table>
		</td>
	</tr>
</table>
</form>
<div align="center"><?php if(isset($_GET['message'])) echo $_GET['message'];?></div>
<br />
<div align="center"><a href="sites.php">Back to Site Management</a></div>
<div align="center"><a href="index.php">Back to Main Menu</a></div>
"
<script type="text/javascript">

function formSubmit(obj)
{
	var retval = "";
	retval = getCheckBoxlList(obj,'avai[]', ',');
	Update.showCheck.value  = retval;
	retval = "";
	retval = getUnCheckBoxlList(obj,'avai[]', ',');
	Update.hidCheck.value  = retval;
	Update.submit();
}

</script>
			<?
			// close connection
			close($link);
			?>
